package com.byxy.action;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;

import com.byxy.entity.User;
import com.byxy.service.UserService;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {
	@Resource
	private UserService userService;
	private String username;
	private String password;
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String login(){
		
		if(ServletActionContext.getRequest().getMethod().equalsIgnoreCase("post")) {
			for(User u:userService.find()) {
				if(username.equals(u.getName())) {
					if(password.equals(u.getPassword())) {
						ServletActionContext.getRequest().getSession().setAttribute("user", u);
						return SUCCESS;
					}
				}
				System.out.println(u.toString());
			}
			
		}
		return "login";
		
	}
}
